package fragments.demo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FragmentsActivity extends Activity {
    /** Called when the activity is first created. */

	Button btnExampleFragment = null;
	Button btnManagerFragment = null;
	Button btnCommunicateWithActivity = null;
	Button btnFragmentCycleLife = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    	
        btnExampleFragment = (Button)this.findViewById(R.id.btnExampleFragment);
        btnManagerFragment = (Button)this.findViewById(R.id.btnManagerFragment);
        btnCommunicateWithActivity = (Button)this.findViewById(R.id.btnCommunicateWithActivity);
        btnFragmentCycleLife = (Button)this.findViewById(R.id.btnFragmentCycleLife);
        
        
        btnExampleFragment.setOnClickListener(new ButtonOnClickListener(FragmentsActivity.this, ExampleFragmentActivity.class));       
        btnManagerFragment.setOnClickListener(new ButtonOnClickListener(FragmentsActivity.this, ManagerFragmentActivity.class));       
        btnCommunicateWithActivity.setOnClickListener(new ButtonOnClickListener(FragmentsActivity.this, CommunicateWithActivityActivity.class));       
        btnFragmentCycleLife.setOnClickListener(new ButtonOnClickListener(FragmentsActivity.this, FragmentCycleLifeActivity.class));       
    }
    
	class ButtonOnClickListener implements OnClickListener{
		private Context context = null;
		private Intent intent = null;
		
		public ButtonOnClickListener() { }
		
		public ButtonOnClickListener(Context context, Class<?> cls) {
			this.context = context;
			this.intent = new Intent(context, cls);
		}
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			this.context.startActivity(intent);
		}
	}
}